
! ! !  PARA USAR COM LMDIF - levenberg marquardt: J por diferencas finitas


	subroutine fcn1(m,n,x,fvec,iflag)
	include 'param_dim.inc'
	double precision x(n)
	double precision fobj
	integer iavalfunct,n,m,ldfjac,metodo
	double precision fvec(m),fjac(NRCX*npar_max)
        integer count1,count2,count_rate,count_max
	data iavalfunct/0/
	iavalfunct=iavalfunct+1


	metodo =1
	if(iflag .eq. 0)then

            write(4,*) '_______________________________________'
            fobj=resid(x,fvec,fjac,m,n,ldfjac,iflag,metodo)    
            write(4,*) '_______________________________________'

	elseif(iflag .eq. 1)then

            call system_clock(count1,count_rate,count_max)
!             write(4,*) 'fcn1 - calculo do vetor residuo - FVEC'
            fobj=resid(x,fvec,fjac,m,n,ldfjac,iflag,metodo)    
            call system_clock(count2,count_rate,count_max)
            r=(count2-count1)
            write(4,*)'tempo avaliacao: (s)',r/count_rate
            write(4,*)
	elseif(iflag .eq. 2)then

            call system_clock(count1,count_rate,count_max)
!             write(4,*) 'fcn1 - calculo do jacobiano de f - FJAC'
            fobj=resid(x,fvec,fjac,m,n,ldfjac,iflag,metodo)    
            call system_clock(count2,count_rate,count_max)
            r=(count2-count1)
            write(4,*)'tempo aval p grad: (s)',r/count_rate
            write(4,*)
	endif



! 	write(*,*)'x: '
! 	write(*,1000)(x(i),i=1,n)
! 	write(*,*)'fvec'
! 	write(*,1001)(fvec(i),i=1,m)

 1000	format(8f10.4)
 1001	format(104f10.4)

 1130   format(22x,3f14.6)
	return
	end	
